package com.sk.bilibili.view.fragment.main.home.dynamic;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.HorizontalAdapter;
import com.sk.bilibili.adapter.vlayout.main.FollowAdapter;
import com.sk.bilibili.adapter.vlayout.main.dynamic.SearchAdapter;
import com.sk.bilibili.adapter.vlayout.main.dynamic.video.VideoAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HeaderAdapter;
import com.sk.bilibili.bean.Dynamic;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.callBack.SearchClickCallBack;
import com.sk.bilibili.callBack.ThemClickCallBack;
import com.sk.bilibili.model.fragment.main.home.dynamic.VideoModel;
import com.sk.bilibili.view.activity.DynamicActivity;
import com.sk.bilibili.view.activity.DynamicSearchActivity;
import com.sk.bilibili.view.activity.MemberActivity;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.activity.VideoSetActivity;
import com.sk.bilibili.view.diy.bottomDialog.LaterBottomDialog;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class VideoFragment extends BaseRefreshFragment<VideoModel> implements SearchClickCallBack, ThemClickCallBack {

    private HorizontalAdapter<FollowThem> themAdapter;
    private VideoAdapter videoAdapter;
    private LaterBottomDialog laterBottomDialog;

    public VideoFragment() {
        laterBottomDialog=new LaterBottomDialog();
    }

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        adapter.addAdapter(new SearchAdapter(getContext(), this));
        adapter.addAdapter(new HeaderAdapter(getContext(), "我的追番·追剧"));
        themAdapter = new HorizontalAdapter<>(getContext(), new FollowAdapter(getContext(), this));
        adapter.addAdapter(themAdapter);
        videoAdapter = new VideoAdapter(getContext(), this);
        adapter.addAdapter(videoAdapter);
    }

    @Override
    public void onClickSearch() {
        DynamicSearchActivity.start(getContext());
    }

    @Override
    public void onThemClick(Integer themId, int selection) {
        ThemActivity.start(getContext(), themId,selection);
    }

    public void loadFollowThemSuccess(List<FollowThem> records) {
        themAdapter.setList(records);
    }

    public void onVideoSetClick(Integer id) {
        VideoSetActivity.start(getContext(), id);
    }

    public void onMemberClick(Integer id) {
        MemberActivity.start(getContext(), id);
    }

    public void refreshSuccess(List<Dynamic> records) {
        videoAdapter.setData(records);
        cancelRefresh();
    }

    public void loadSuccess(List<Dynamic> records) {
        videoAdapter.addData(records);
    }

    public void onMoreClick(Integer id) {
        laterBottomDialog.show(getChildFragmentManager(),id);
    }

    public void onForwardClick(Integer id) {
        DynamicActivity.start(getContext(),0,id);
    }

    public void onPraiseClick(Integer id) {
        model.praiseVideoSet(id);
    }

    public void praiseVideoSetSuccess() {
        toast("操作成功");
    }

}